import os  
import requests  

# 设置下载目录  
download_folder = "downloaded_images"  
if not os.path.exists(download_folder):  
    os.makedirs(download_folder)  

# 原始URL  
original_url = "https://oss-img.mengguzhiai.com/xr/016011/image/248.jpg"  
  
# 提取基本URL（不包含图片编号和扩展名）  
base_url = original_url.rsplit('/', 2)[0]  
base_url = "https://oss-img.mengguzhiai.com/xr/016011/image" 
print(base_url)
# 起始和结束的图片编号  
start_number = 220  
end_number = 222 
  
# 生成URL列表  
image_urls = [f"{base_url}/{i}.jpg" for i in range(start_number, end_number + 1)]  
   
# 遍历URL列表并下载图片  
for idx, url in enumerate(image_urls):  
    # 从URL中提取文件名（这里简单地从URL的最后一部分获取，可能需要根据实际情况调整）  
    filename = os.path.join(download_folder, os.path.basename(url))  
      
    # 发送HTTP GET请求获取图片  
    response = requests.get(url)  
      
    # 检查请求是否成功  
    if response.status_code == 200:  
        # 将图片内容写入文件  
        with open(filename, 'wb') as f:  
            f.write(response.content)  
        print(f"Downloaded {filename}")  
    else:  
        print(f"Failed to download {url} with status code {response.status_code}")  
  
print("Download completed.")